namespace EPPlayer
{
    /// <summary>
    /// GoverningAptitude is used to create AttributeFilters
    /// </summary>
    public class Skill : ValueAttribute, IAttachableAttribute 
    {
        protected readonly string GoverningAptitude;
        protected readonly bool AllowsDefaulting;
        /// <summary>
        /// Active or Knowledge
        /// </summary>
        protected readonly string Category;
        protected readonly string Group;
        public const string AttributeColor = "Skill";
        private bool IsField;

        internal Skill(string Name, string Apt, bool Default, string Category, string Group, string Description = null)
            :base (Name, AttributeColor, 0, Description)
        {
            this.GoverningAptitude = Apt;
            this.AllowsDefaulting = Default;
            this.Category = Category;
            this.Group = Group;
            this.IsField = Name.Contains(":");
        }
        public string category
        {
            get { return this.Category; }
        }
        public string governingAptitude
        {
            get { return this.GoverningAptitude; }
        }
        public bool allowsDefaulting
        {
            get { return this.AllowsDefaulting; }
        }
        public string group
        {
            get { return this.Group; }
        }
        public bool isFieldSkill
        {
            get { return this.IsField; }
        }

        public new void OnAttach(Entity Entity)
        {
            base.OnAttach(Entity);

            AttributeFilter Af = new AttributeFilter(this.Name, this.Color, this, this,
                att => att + (Entity[this.governingAptitude] as ValueAttribute).cookedValue);
            Af.Owner = this;
            Entity.Add(Af);
            (Entity[this.governingAptitude] as ValueAttribute).AddDependent(Af);
        }
    }
}